//
//  SAStatisticsResultsCell.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/7/23.
//

#import "SAStatisticsResultsCell.h"
#import "SAStatisticsResultsModel.h"

@interface SAStatisticsResultsCell ()

@property (nonatomic, strong) UILabel *empLab;
@property (nonatomic, strong) UILabel *saleLab;
@property (nonatomic, strong) UILabel *accountedLab;
@property (nonatomic, strong) UILabel *taskLab;
@property (nonatomic, strong) UILabel *completeLab;
@property (nonatomic, strong) UIView *line;

@end

@implementation SAStatisticsResultsCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAStatisticsResultsModel *)model {
    _model = model;
    self.empLab.text = model.empName;
    self.saleLab.text = [NSString stringWithFormat:@"%0.2lf",[model.price doubleValue]/100.f].getEffectivePointString;
    if ([model.proportion isEqualToString:@"0%"]) {
        self.accountedLab.text = @"0%";
    }else {
        self.accountedLab.text = model.proportion;
    }
    
    self.taskLab.text = [NSString stringWithFormat:@"%0.2lf",[model.prepareWorkAmount doubleValue]/100.f].getEffectivePointString;
    self.completeLab.text = model.achievementRate;
}

-(void)initUI {
    [self.contentView addSubview:self.line];
    [self.contentView addSubview:self.empLab];
    [self.contentView addSubview:self.saleLab];
    [self.contentView addSubview:self.accountedLab];
    [self.contentView addSubview:self.taskLab];
    [self.contentView addSubview:self.completeLab];
}

-(UILabel *)empLab {
    if (!_empLab) {
        _empLab = [[UILabel alloc] initWithFrame:SARectMake(0, 0, 80, 45)];
        _empLab.textColor = kBlackColor;
        _empLab.textAlignment = NSTextAlignmentCenter;
        _empLab.font = kFont(15);
        _empLab.adjustsFontSizeToFitWidth = YES;
        _empLab.minimumScaleFactor = 0.8;
    }
    return _empLab;
}

-(UILabel *)saleLab {
    if (!_saleLab) {
        _saleLab = [[UILabel alloc] initWithFrame:SARectMake(81, 0, 83, 45)];
        _saleLab.textColor = kBlackColor;
        _saleLab.font = kFont(15);
        _saleLab.textAlignment = NSTextAlignmentCenter;
        _saleLab.adjustsFontSizeToFitWidth = YES;
        _saleLab.minimumScaleFactor = 0.8;
    }
    return _saleLab;
}

-(UILabel *)accountedLab {
    if (!_accountedLab) {
        _accountedLab = [[UILabel alloc] initWithFrame:SARectMake(166, 0, 63, 45)];
        _accountedLab.textColor = kBlackColor;
        _accountedLab.font = kFont(15);
        _accountedLab.textAlignment = NSTextAlignmentCenter;
        _accountedLab.adjustsFontSizeToFitWidth = YES;
        _accountedLab.minimumScaleFactor = 0.8;
    }
    return _accountedLab;
}

-(UILabel *)taskLab {
    if (!_taskLab) {
        _taskLab = [[UILabel alloc] initWithFrame:SARectMake(231, 0, 83, 45)];
        _taskLab.textColor = kBlackColor;
        _taskLab.font = kFont(15);
        _taskLab.textAlignment = NSTextAlignmentCenter;
        _taskLab.adjustsFontSizeToFitWidth = YES;
        _taskLab.minimumScaleFactor = 0.8;
    }
    return _taskLab;
}

-(UILabel *)completeLab {
    if (!_completeLab) {
        _completeLab = [[UILabel alloc] initWithFrame:SARectMake(315, 0, 60, 45)];
        _completeLab.textColor = kBlackColor;
        _completeLab.font = kFont(15);
        _completeLab.textAlignment = NSTextAlignmentCenter;
        _completeLab.adjustsFontSizeToFitWidth = YES;
        _completeLab.minimumScaleFactor = 0.8;
    }
    return _completeLab;
}

-(UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(45), kScreenWidth, kScaleNum(1))];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}

@end
